package com.sos.widget.util

import android.graphics.Color
import kotlin.math.roundToInt

/**
 * @Description
 * @Author 梁浩文
 * @Date 2023/3/31 11:23
 */
/**
 * 设置颜色透明一半
 * @param color
 * @return
 */
fun Int.translucentColor(): Int {
    val factor = 0.5f
    val alpha = (Color.alpha(this) * factor).roundToInt()
    val red = Color.red(this)
    val green = Color.green(this)
    val blue = Color.blue(this)
    return Color.argb(alpha, red, green, blue)
}
/*
*设置颜色透明
*/
fun Int.translucentColor(alpha:Float):Int {
    val factor = alpha
    val alpha = (Color.alpha(this) * factor).roundToInt()
    val red = Color.red(this)
    val green = Color.green(this)
    val blue = Color.blue(this)
    return Color.argb(alpha, red, green, blue)
}

fun Int.translucentColorPercent(alpha:Float): Int {
    val factor = alpha*0.01f
    val alpha = (Color.alpha(this) * factor).roundToInt()
    val red = Color.red(this)
    val green = Color.green(this)
    val blue = Color.blue(this)
    return Color.argb(alpha, red, green, blue)
}